var http = require("http");
var url = require("url");

function start(route) {
    function onRequest(request, response) {
        var pathname = url.parse(request.url).pathname;
        // 最后查到因为“/favicon.ico”才重复执行多一次。要实现执行只执行一次，发须进行判断
        if (pathname === '/favicon.ico') return;//不去掉这个会有一次默认的请求

        console.log("我的个路径啊 " + pathname + " received.");
        route(pathname);
        response.writeHead(200, {"Content-Type": "text/plain"});
        response.write("Hello World");
        response.end();


    }

    http.createServer(onRequest).listen(8888);
    console.log("Server has started.");
}

exports.start = start;